package com.ctn.bootstarp.tags.ui;

import java.util.List;

import javax.servlet.jsp.JspException;

import tldgen.Tag;
import tldgen.TagAttribute;

import com.ctn.bootstarp.tags.AppTag;

/**
 * @author weiqi
 * @date 2013年8月6日
 */
@Tag
public class TableTag extends AppTag {
	
	private static final long serialVersionUID = -715830415642225967L;
	
	private static String table = "<table id=\"contentTable\" "
					+ "class=\"table{EXTEND-CSS}\">";
	private StringBuffer extendCss = new StringBuffer();
	
	private StringBuffer thead = new StringBuffer("<thead>");
	private StringBuffer tbody = new StringBuffer("<tbody>");
	
	/**数据集**/
	private List<Object> items;
	
	@TagAttribute(description="the table datas")
	public void setItems(List<Object> items) {
		this.items = items;
	}
	
	private String emptyMsg = "no data found!";
	
	@TagAttribute(description="when no data , what is default show")
	public void setEmptyMsg(String emptyMsg) {
		this.emptyMsg = emptyMsg;
	}

	/**条纹**/
	private boolean striped;
	
	@TagAttribute(description="to show table is striped")
	public void setStriped(boolean striped) {
		this.striped = striped;
	}
	
	/**边框和圆角**/
	private boolean bordered;

	@TagAttribute(description="to show table is bordered")
	public void setBordered(boolean bordered) {
		this.bordered = bordered;
	}
	
	/**悬停样式**/
	private boolean hover;

	@TagAttribute(description="to show table row is hoverd style")
	public void setHover(boolean hover) {
		this.hover = hover;
	}
	
	/**缩减表格一半**/
	private boolean condensed;

	@TagAttribute(description="to show table is condensed half")
	public void setCondensed(boolean condensed) {
		this.condensed = condensed;
	}

	public void addThead(String head){
		this.thead.append(head);
	}
	
	public void addTrow(){
		
	}
	
	@Override
	public int doStartTag() throws JspException {
		if(striped){
			this.extendCss.append(" table-striped");
		}
		if(bordered){
			this.extendCss.append(" table-bordered");
		}
		if(hover){
			this.extendCss.append(" table-hober");
		}
		if(condensed){
			this.extendCss.append(" table-condensed");
		}
		table = table.replace("{EXTEND-CSS}", this.extendCss.toString());
		return super.doStartTag();
	}
	
	@Override
	public void doInitBody() throws JspException {
		thead.append("</thead>");
		super.doInitBody();
	}
	
	@Override
	public int doAfterBody() throws JspException {
		tbody.append("</tbody>");
		return super.doAfterBody();
	}

}
